package jdbc;

import jdbc.common.InputUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class JDBCDemo11 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入用户名：");
        String username = scanner.nextLine();
        System.out.println("输入新的密码：");
        String password = scanner.nextLine();
        System.out.println("输入新的昵称：");
        String nickname = scanner.nextLine();
        try(Connection connection = DBUtil.getConnection()){
            String sql = "UPDATE userinfo " +
                    "SET password=?,nickname=? " +
                    "WHERE username=?";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1,password);
            preparedStatement.setString(2,nickname);
            preparedStatement.setString(3,username);
            int count = preparedStatement.executeUpdate();
            System.out.println(count>0?"修改成功":"修改失败");
        }catch (SQLException e){
            e.printStackTrace();
        }
    }
}